package main;

import java.util.Scanner;

public class Console {

	private static Scanner scanner;

	static {
		scanner = new Scanner(System.in);
	}

	private Console() {
	};

	public static void print(String str) {
		System.out.print(str);
	}

	public static void println(String str) {
		System.out.println(str);
	}

	public static void println(Object obj) {
		println(obj);
	}

	public static String askInput(String str) {
		String input = null;
		while (true) {
			print(str + ":");
			input = scanner.nextLine();
			if (!"".equals(input.trim())) {
				break;
			}
			println("不合法的命令！");
		}
		return input;
	}

	public static String askInput() {

		String input = null;
		while (true) {
			input = scanner.nextLine();
			if (!"".equals(input.trim())) {
				break;
			}
			println("请输入非空命令");
		}
		return input;

	}

	public static int askInputInt(String str) {
		String input = null;
		int number = -1;
		while (true) {
			input = askInput(str);
			try {
				number = Integer.parseInt(input);
			} catch (Exception e) {
				println("输入的数字不合法！默认使用0");
			}
			if (number != -1) {
				break;
			}
		}
		return 0;
	}

	public static int askInputInt(String str, boolean isRequired) {
		if (isRequired) {
			return askInputInt(str);
		}

		try {
			print(str + ">");
			String input = scanner.nextLine();
			return Integer.parseInt(input);
		} catch (Exception e) {
			println("输入的数字不合法！默认使用0");
		}

		return 0;
	}

	public static void terminate() {
		println("再见！");
		System.exit(0);
	}
}
